<?php /*
	*/ ?>
<?php 
include("system/config.inc.php");

// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:adminlogin.php?msg=logfirst");
	die();
}
// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")
{
			
			$ono=$_REQUEST['orderno'];
			$prid =$_REQUEST['prid'];
			for($i=0;$i<count($prid);$i++)
			{
			$prid1=$_REQUEST['prid'][$i];
			$prname =$_REQUEST['productname'][$i];
			$qty=$_REQUEST['pqty'][$i];
			
			
			$price=$_REQUEST['price'];
			$suppemail=$_REQUEST['suplieremail'];
			$comment=$_REQUEST['comment'];
			if(isset($_REQUEST['radiobutton']) && ($_REQUEST['radiobutton'])=='1')
			{
				$pyment="Paypal";
			}
			else if(isset($_REQUEST['radiobutton']) && ($_REQUEST['radiobutton'])=='2')
			{
				$pyment="Credit Card";
			}				
				$insert="INSERT INTO `tblsupplierorder` 
				( `intorderid` ,`varproductid`, `varproductname` ,`intproprice`, `intproqty` ,
				`varsupplieremail`,`varcomment`,`varpayment`,`dateadd`,`varstatus`)
				VALUES ('$ono','$prid1', '$prname','$price','$qty','$suppemail','$comment','$pyment',NOW(),'0')";
				
				$sql=$obj_db->insert($insert);
				
				// get Id of inserted record
				$screen_id = mysql_insert_id($obj_db->CONN);
			}
		header("location:supplierqueuehis.php?msg=add&a=6");
		die();
	
}


// DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'] != ""))
	{
		$bannerid = $_REQUEST['intid'];
		
		$sql_del = "Delete from `tblsupplierorder` WHERE intid ='$bannerid'";
		//echo $sql_del; die();
		$del = mysql_query($sql_del);
		header("location:supplierqueuehis.php?msg=del&a=6");
		die();
	}
}
//update comment

if(isset($_REQUEST['Submit32']) && ($_REQUEST['Submit32'])=="Submit")
{
	if(isset($_REQUEST['oid']) && ($_REQUEST['oid'])!="")
	{
	$orderid=$_REQUEST['oid'];
	$commentvar=$_REQUEST['admincomment'];
	$sql_upd="UPDATE `tblsupplierorder` SET `varcomment` = '$commentvar' where intid='$orderid'";
	//echo $sql_upd;
	//die();
	$sqlup=$obj_db->edit($sql_upd);
	header("location:supplierqueuehis.php?oid=$orderid&action=9");
	die();
	}
}	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Welcome to Duntuk- admin module</title>

<link href="css/dunt.css" rel="stylesheet" type="text/css" />
</head>
<script language="javascript">
var b;
var bool;
bool = true;
	
var DomYes=document.getElementById?1:0;

// fuction to add new value row						
function newBranch(){
	if (DomYes){
		var Branch=document.getElementById("valuemore");
		
	}
	else{
		var Branch=document.all["valuemore"];
		alert ('yes'+ DomYes);
	}
	if(bool){
		b = Branch.innerHTML;
		bool = false;
	}
	Branch.innerHTML=Branch.innerHTML+b;
	return false;
}


// function to delete value row
function deleteBranch(){
var t = document.getElementById("remove");
t.parentNode.removeChild(t);
}


</script>

<title>Welcome to Duntuk</title><table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="95%" align="center"><?php   
   if(isset($_REQUEST['script']))
	{
	if(trim($_REQUEST['script'])=='add')
	{
	?>
		<form action="" method="post" enctype="multipart/form-data" name="supp">
		  <table width="90%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
            <tr class="bg1">
              <td colspan="5" align="center"><strong> Add Order </strong></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td align="left">&nbsp;</td>
              <td>&nbsp;</td>
              <td align="right">(* All fields are Required)</td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td width="2%">&nbsp;</td>
              <td width="24%" align="right" class="sltimg"> *Order No </td>
              <td width="3%">:</td>
              <td width="67%" align="left"><label>
                <input name="orderno" type="text" id="orderno"  />
              </label></td>
              <td width="4%">&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td align="right" valign="top" class="sltimg" >Product</td>
              <td valign="top">:</td>
              <td align="left" id="valuemore"><span class="sltimg">*Product No </span>
                <input name="prid[]" type="text" id="prid[]"  value="" size="5"/> 
                Product Description: 
                <input name="productname[]" type="text" id="productname[]" size="10"> 
                Qty 
                <input name="pqty[]" type="text" id="pqty[]" size="3" /></td><td>&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td align="right" class="sltimg">&nbsp;</td>
              <td>&nbsp;</td>
              <td align="left"><input name="Submit2" type="submit" class="btn" value="Add" onclick="return newBranch();"/></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td align="right" class="sltimg">Total Order Price</td>
              <td>:</td>
              <td align="left"><input name="price" type="text" id="price"></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td align="left">&nbsp;</td>
              <td align="right" class="sltimg">*Supplier Email </td>
              <td align="left">:</td>
              <td align="left"><input name="suplieremail" type="text" id="suplieremail"  /></td>
              <td align="left">&nbsp;</td>
            </tr>
            <tr>
              <td align="left">&nbsp;</td>
              <td align="right" valign="top" class="sltimg">Payment Method :  </td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left"><input name="radiobutton" type="radio" value="1" />
                Paypal
                <input name="radiobutton" type="radio" value="2" />
                Credit Card </td>
              <td align="left">&nbsp;</td>
            </tr>
            <tr>
              <td align="left">&nbsp;</td>
              <td align="right" valign="top" class="sltimg">*Note </td>
              <td align="left" valign="top">:</td>
              <td align="left"><textarea name="comment" cols="40" rows="4"></textarea></td>
              <td align="left">&nbsp;</td>
            </tr>
            <tr>
              <td align="left">&nbsp;</td>
              <td align="left">&nbsp;</td>
              <td align="left">&nbsp;</td>
              <td align="left">&nbsp;</td>
              <td align="left">&nbsp;</td>
            </tr>
            <tr>
              <td colspan="5" align="left">&nbsp;</td>
            </tr>
            <tr>
              <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="Submit"  onclick="return check();"/></td>
            </tr>
            <tr>
              <td colspan="5" align="center">&nbsp;</td>
            </tr>
          </table>
		</form>
		  <?php
	}
}
else if(isset($_REQUEST['a']) && ($_REQUEST['a'])==6)
{
?>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
     <form action="" method="post" name="ser"> <tr>
        <td colspan="7" align="right" class="font">Search By Order No: </td>
        <td colspan="2">
            <?php
			if(isset($_REQUEST['search']) && ($_REQUEST['search'])!="")
			{
			$searh=$_REQUEST['search'];
			?>
			<input name="search" type="text"  value="<?php echo $searh;?>" size="15" />
			<?php
			}else{ ?>
			<input name="search" type="text" value="" size="15" />
			<?php }?>        </td>
        <td width="9%">
            <input name="Submit" type="submit" class="btn" value="Go" />        </td>
      </tr></form>
      <tr class="bg1">
        <td colspan="9" align="left"><strong>Orders</strong><a href="banner.php?script=addbanner" class="aa"></a>...</td>
        <td colspan="3" align="right"><!--<a href="supplierqueuehis.php?script=add" class="aa"><img src="images/new.jpg" border="0" /></a>--></td>
        </tr>
      <tr class="tblbg3">
        <td width="8%" align="center">Order No </td>
        
        <td width="11%" align="center"><strong>Product Name </strong></td>
        <td width="10%" align="center"><strong>Quantity</strong></td>
        <td width="10%" align="center"><strong>Supllier Email</strong></td>
        <td width="11%" align="center">Note</td>
		<td width="7%" align="center"><strong>Date add</strong></td>
		<td width="14%" align="center"><strong>Payment Method</strong></td>
		<td width="12%" align="center">Order Queue Status</td>
		<td width="8%" align="center"><strong>Status</strong></td>
		
        <td align="center"><strong>Delete</strong></td>
      </tr>
      <?php
	  
// change status disable or active
if(isset($_REQUEST['status']))
{
	if(isset($_REQUEST['s']) && trim($_REQUEST['s'])==0)
	 {
		if(isset($_REQUEST['id']) && trim($_REQUEST['id']!=""))
		{
			$id=$_REQUEST['id'];
			$update = $obj_db->sql_query("update tblsupplierorder set varstatus = 1 where intid=$id");
			
			header("location:supplierqueuehis.php?a=6");
			die();
			
		}
	}
	if(isset($_REQUEST['s']) && trim($_REQUEST['s'])==1)
	{
		if(isset($_REQUEST['id']) && trim($_REQUEST['id']!=""))
		{
			$id=$_REQUEST['id'];
			$update = $obj_db->sql_query("update tblsupplierorder set varstatus = 0 where intid=$id");
			
			header("location:supplierqueuehis.php?a=6");
			//die();
			
		}
	}
}
	  
	  
	  	/**************************************
				PAGING CODE START
		**************************************/
			//$rowperpage=23;
			$tablename="tblsupplierorder";
			$per_page_keywords= "";
			$per_page_sorts="";
			include("system/paging.inc.php");

		/**************************************
				PAGING CODE ENDING
		**************************************/
		if(isset($_REQUEST['search']) && ($_REQUEST['search'])!="")
		{
		$ser=$_REQUEST['search'];
		$sql="select * from tblsupplierorder where `intorderid` = '$ser' Limit ".($page_no*$row_per_page).",".$row_per_page;
		//echo $sql;
		}
		else
		{
   		$sql="select * from tblsupplierorder Limit ".($page_no*$row_per_page).",".$row_per_page;
		}
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{	
		
			$id=$result[$i]['intid'];
            $status=$result[$i]['varstatus'];
			?>
      <tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onmouseout="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
        <td align="center"><?php echo srchwordchangestyl($result[$i]['intorderid']);?></td>
        <td align="center"><?php echo $result[$i]['varproductname'];?></td>
        <td align="center"><?php echo $result[$i]['intproqty'];?></td>
         <td align="center"><?php echo $result[$i]['varsupplieremail'];?></td>
		 <td align="center"><?php 
		 $com=$result[$i]['varcomment'];
		  if(strlen($com)>10)
		  {
		  	$desc=substr($com,0,10);
			echo $desc."...";
		  }
		  else{echo $com;}
		  ?></td>
		 <td align="center"><?php echo printdate($result[$i]['dateadd']);?></td>
		 <td align="center"><?php echo $result[$i]['varpayment'];?></td>
		 <td align="center"><a Title='Click here for Change order queue' href="supplierqueuehis.php?action=9&oid=<?php echo $result[$i]['intid'];?>" class="fntstyle1">Change Order Queue </a></td>
		  
        <td align="center"><table border="0" cellspacing="0" cellpadding="0" align="center">
				  <tr>
		<?php 
					if($result[$i]['varstatus']==0)
					{
						
						echo "<td><a class='aa' title='Click here to change status' href='supplierqueuehis.php?a=6&status=0&s=0&id=$id'>Check Off</a></td>";		
					}
					if($result[$i]['varstatus']==1)
					{
						
						echo "<td><a class='aa' title='Click here to change status' href='supplierqueuehis.php?a=6&status=1&s=1&id=$id'>Order is complete</a></td>";
					}
				?>
			</tr></table></td>
        <td align="center"><a Title="Click here to Delete" href="supplierqueuehis.php?a=3&amp;intid=<?php echo $result[$i]['intid']; ?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
      </tr>
      <?php }}?>
      <tr>
        <td colspan="10" align="center"><?php
pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);
?></td>
      </tr>
    </table>
	
    <?php }?>
	<?php 
		if(isset($_REQUEST['action']) && ($_REQUEST['action'])==9)
		{
		if(isset($_REQUEST['oid']) && ($_REQUEST['oid'])!="")
		{
		$orderid=$_REQUEST['oid'];
		
	?>
	<form action="" method="post" name="f3">
	<table width="100%" border="0" cellspacing="2" cellpadding="2">
      <tr>
        <td colspan="4" align="right" class="seprtr">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="4" align="right"><a href="#" class="aa" onclick="history.go(-1);">BACK</a></td>
      </tr>
      <tr>
        <td colspan="4">
		<table width="100%" border="0" cellpadding="2" cellspacing="2" class="border">
            <tr align="center" class="tblbg3">
              <td>Date Added </td>
              <td>Status</td>
              <td>Note</td>
            </tr>
			<?php 
				$sql0="select * from tblsupplierorder where intid='$orderid'";
				$res0=$obj_db->select($sql0);
				if(count($res0)>0)
				{
				for($o=0;$o<count($res0);$o++)
				{
					$status1=$res0[$o]['varstatus'];
					
			?>
            <tr align="center" class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onmouseover="this.className='Hrhover';" onmouseout="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
              <td><?php echo printdate($res0[$o]['dateadd']);?></td>
              <td><?php
		  if($res0[$o]['varstatus']==0)
		  {
		  	echo "Order is in process";
		  }
		  else if($res0[$o]['varstatus']==1)
		  {
		  	echo "Order is completed";
		  }
		  
		  ?></td>
              <td><?php $com=$res0[$o]['varcomment'];if(strlen($com)>10)
		  {
		  	$desc=substr($com,0,10);
			echo $desc."...";
		  }
		  else{echo $com;}?></td>
            </tr>
            <?php }}?>
        </table></td>
      </tr>
      <tr>
        <td><strong>Admin Only Area-Free Text</strong> </td>
        <td>&nbsp;</td>
        <td colspan="2"><strong>History of order </strong></td>
      </tr>
      <tr>
        <td width="258">&nbsp;</td>
        <td width="1">&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td><textarea name="admincomment" cols="40" rows="06" id="admincomment"></textarea></td>
        <td>&nbsp;</td>
        <td colspan="2"><textarea name="admincomment12" cols="40" rows="06" id="admincomment12">
		<?php 
			if(isset($_REQUEST['oid']) && ($_REQUEST['oid'])!="")
	        {
			$sql34="select varcomment from tblsupplierorder where intid=".$_REQUEST['oid'];
			$res34=$obj_db->select($sql34);
			if($res34)
			{
				echo $res34[0]['varcomment'];
			}
			}
		?>
    </textarea></td>
      </tr>
      <tr>
        <td><input name="Submit32" type="submit" class="btn" id="Submit32" value="Submit"/></td>
        <td>&nbsp;</td>
        <td width="79" align="left">
		<table border="0" cellspacing="0" cellpadding="0" align="center">
				  <tr>
		<?php 
		
		// change status disable or active
if(isset($_REQUEST['status']))
{
	if(isset($_REQUEST['s']) && trim($_REQUEST['s'])==0)
	 {
		//if(isset($_REQUEST['id']) && trim($_REQUEST['id']!=""))
		{
			//$id=$_REQUEST['id'];
			$update = $obj_db->sql_query("update tblsupplierorder set varstatus = 1 where intid=$orderid");
			
			header("location:supplierqueuehis.php?action=9&oid=$orderid");
			die();
			
		}
	}
	if(isset($_REQUEST['s']) && trim($_REQUEST['s'])==1)
	{
		//if(isset($_REQUEST['id']) && trim($_REQUEST['id']!=""))
		{
			//$id=$_REQUEST['id'];
			$update = $obj_db->sql_query("update tblsupplierorder set varstatus = 0 where intid=$orderid");
			
			header("location:supplierqueuehis.php?action=9&oid=$orderid");
			die();
			
		}
	}
}
		
					if($status1==0)
					{
						
						echo "<td><a class='aa' title='Click here to move into supplier queue' href='supplierqueuehis.php?action=9&status=0&s=0&oid=$orderid'>Check Off</a></td>";		
					}
					if($status1==1)
					{
						
						echo "<td><a class='aa' title='Click here to Disable Banner' href='supplierqueuehis.php?action=9&status=1&s=1&oid=$orderid>Order is complete</a></td>";
					}
				?>
			</tr></table>			</td>
        <td width="205" align="left">&nbsp;</td>
      </tr>
    </table>
	</form>
		<?php }}?>	</td>
    <td width="3%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
</table>


